Ext.define('Zm.view.nav.DevTree', {
    extend: 'Ext.tree.Panel',
    alias: 'widget.devtree',
    requires:[
        'Zm.view.dev.SelectDev',
        'Zm.store.DevTree',
        'Zm.i18n.Lang'
    ],
    initComponent: function() {
        var me = this,
            lang = Zm.i18n.Lang;
        me.contextMenu = Ext.create('Ext.menu.Menu', {
            items: [{
                text:lang.tAdd,
                iconCls:'devadd',
                handler:Ext.bind(me.doAdd,me)
            },{
                text:lang.tDel,
                iconCls:'devdel',
                handler:Ext.bind(me.doDel,me)
            },{
                text:lang.tRename,
                iconCls:'devren',
                handler:Ext.bind(me.doRen,me)
            },'-',{
                text:lang.tRefresh,
                iconCls:'refresh',
                handler:Ext.bind(me.doRef,me)
            }]
        });
        Ext.apply(me,{
            title:lang.tDevTree,
            rootVisible: false,
            store:'DevTree',
            useArrows: true,
            viewConfig: {
                stripeRows: true,
                listeners: {
                    itemcontextmenu:me.onItemContextMenu,
                    containercontextmenu:me.onContextMenu
                }
            }
        });
        me.addEvents('devadd','devdel','devrefresh','devren');
        me.callParent(arguments);
    },
    onItemContextMenu:function(view, rec, node, index, e){
        var me = view.up('devtree');
        e.stopEvent();
        me.contextMenu.showAt(e.getXY());
        return false;
    },
    onContextMenu:function(view,e,eOpts){
        var me = view.up('devtree');
        e.stopEvent();
        me.contextMenu.showAt(e.getXY());
        return false;
    },
    doAdd:function(){
        var me = this,view,
            selMode = me.getSelectionModel(),
            node = selMode.getLastSelected();
        if(node){
            
        }else{
            node = me.getRootNode();
        }
        me.fireEvent('devadd',me,node);
    },
    doDel:function(){
        var me = this,view,
            selMode = me.getSelectionModel(),
            node = selMode.getLastSelected();
        if(node){
            me.fireEvent('devdel',me,node);
        }
    },
    doRen:function(){
        var me = this,view,
            selMode = me.getSelectionModel(),
            node = selMode.getLastSelected();
        if(node){
            me.fireEvent('devren',me,node);
        }
    },
    doRef:function(){
        var me = this;
        me.fireEvent('devrefresh',me);
    }
});
